﻿using SBlogCore.WebAdminApplication.SysManager.Dto;
using SBlogCore.WebAdminApplication.SysManager.IServices;

namespace SBlogCore.WebAdminApplication.SysManager.Controller
{
    /// <summary>
    /// 菜单管理
    /// </summary>
    public class SysMenuSysManagerController: AuthorizeBaseController
    {
        private readonly ISysMenuManagerService _sysManager;
        public SysMenuSysManagerController(ISysMenuManagerService sysManager)
        {
            _sysManager = sysManager;
        }
        /// <summary>
        /// 加载数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysMenuOutPut>> GetMenuList()
        {
            return await _sysManager.GetMenuList();
        }

        /// <summary>
        /// 获取Value-Label格式的选项数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysMenuOptions>> GetMenuOptions()
        {
            List<SysMenuOptions> res = await _sysManager.GetMenuOptions();
            return res;
        }
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public  async  Task UpdateMenu(SysMenuEditInPut input)
        {
            await _sysManager.UpdateMenu(input);
        }

        /// <summary>
        /// 菜单添加接口
        /// </summary>
        /// <param name="inPut"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task AddMenu(SysMenuInPut inPut)
        {
            await _sysManager.AddMenu(inPut);
        }
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task Delete(List<long> ids)
        {
            if (!ids.Any())
            {
                throw SBlogCoreException.Say($"id不能为空！");
            }
            await _sysManager.Delete(ids.ToArray());
        }
    }
}
